package pildoras;

import java.awt.Color;

import scenes.Nivel;

import Calculos.CalculadoraDeVersor;
import Calculos.VersorCalculable;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.colissions.CollisionDetector;

import componentes.Ladrillo;
import componentes.Paleta;

public abstract class Pildora extends GameComponent<Nivel> implements VersorCalculable{

	private Circle cuerpo;
	private Ladrillo ladrillo;
	private int radius = 5;
	private boolean estoyViva = false;
	private double sentidoEnX;
	private double sentidoEnY = 100;
	

	public Pildora(Color color, Ladrillo ladrillo) {
		this.cuerpo = new Circle(color, this.radius);
		this.setX(ladrillo.getX() + ladrillo.getAppearance().getWidth() / 2);
		this.setY(ladrillo.getY());
		this.ladrillo = ladrillo;
		this.ladrillo.addPildora(this);
	}
	
	@Override
	public void onSceneActivated() {
		super.onSceneActivated();
	}

	@Override
	public void update(DeltaState deltaState) {
		Paleta paleta = this.getScene().getPaleta();
		if (this.estoyViva) {
			if (!CollisionDetector.INSTANCE.collidesCircleAgainstRect(this
					.getX(), this.getY(), this.radius, paleta.getX(), paleta
					.getY(), paleta.getAppearance().getWidth(), paleta
					.getAppearance().getHeight())) {
//				CalculadoraDeVersor.calculame(this);
				this.move(0, this.sentidoEnY * deltaState.getDelta());
			} else {
				this.choqueConPaleta();
				this.destroy();
			}

		}
	}

	protected abstract void choqueConPaleta();

	public void activate() {
		this.estoyViva = true;
		this.setAppearance(this.cuerpo);
	}
	

	public void setVersor(double x, double y) {
		this.sentidoEnX = 0;
		this.sentidoEnY = y;
		
	}

}
